
use rsa::{Pkcs1v15Encrypt, RsaPrivateKey, RsaPublicKey};
use rand::rngs::StdRng;
use rand::SeedableRng;
fn main() {

    let mut rng = StdRng::from_entropy();
    println!("rng{:#?}",rng);
    let bits = 2048;
    let priv_key = RsaPrivateKey::new(&mut rng, bits).expect("failed to generate a key");
 //   println!("private key:{:#?}",priv_key);
    let pub_key = RsaPublicKey::from(&priv_key);
//    println!("public key:{:#?}",pub_key);
    // Encrypt
    let data = "hello world 的话的风格和的风格和的风格和".as_bytes();
    let enc_data = pub_key.encrypt(&mut rng, Pkcs1v15Encrypt, &data[..]).expect("failed to encrypt");
    println!("encrypted data:{:#?}",enc_data);
    let dec_data = priv_key.decrypt(Pkcs1v15Encrypt, &enc_data).expect("failed to decrypt");
    let decrypted_str = String::from_utf8_lossy(&dec_data);
    println!("decrypted data:{:#?}",decrypted_str);
  //  assert_eq!(&data[..], &dec_data[..]);


    println!("Hello, world!");
}
